﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TresselLS
{
    class StatusRegister
    {
        public bool overflowOnAdd;
        public bool overflowOnSubtract;
        public bool overflowOnMultiply;
        public bool overflowOnDivide;
        public bool shiftTooLarge;
        public bool rotateTooLarge;
        public bool addressBeforeStart;
        public bool addressAfterStart;
        public bool divideByZero;
        public bool overflowOnAbsolute;
        public bool overflowOnLDN;
        public bool unused11;
        public bool unused12;
        public bool unused13;
        public bool unused14;
        public bool unused15;
        public bool unused16;
        public bool unused17;
        public bool unused18;
        public bool unused19;
        public bool unused20;
        public bool unused21;
        public bool unused22;
        public bool unused23;

        public void Clear()
        {
            this.overflowOnAdd = false;
            this.overflowOnSubtract = false;
            this.overflowOnMultiply = false;
            this.overflowOnDivide = false;
            this.shiftTooLarge = false;
            this.rotateTooLarge = false;
            this.addressBeforeStart = false;
            this.addressAfterStart = false;
            this.divideByZero = false;
            this.overflowOnAbsolute = false;
            this.overflowOnLDN = false;
            this.unused11 = false;
            this.unused12 = false;
            this.unused13 = false;
            this.unused14 = false;
            this.unused15 = false;
            this.unused16 = false;
            this.unused17 = false;
            this.unused18 = false;
            this.unused19 = false;
            this.unused20 = false;
            this.unused21 = false;
            this.unused22 = false;
            this.unused23 = false;
        }
        public string ToBin()
        {
            /*!
            Procedure Name: ToBin
            Description: Provides the binary version of the status register
            Input Parameters: none
            Output Parameters: none
            Errors Conditions Tested:
            Error Messages Generated:
            Original Author: SH, RM
            Procedure Creation Date: 11/21/2009
            Modification Log:
            Coding standards met: SR
            Testing standards met: RM
            !*/
            return ((Convert.ToInt32(unused23)).ToString()
                + (Convert.ToInt32(unused22)).ToString()
                + (Convert.ToInt32(unused21)).ToString()
                + (Convert.ToInt32(unused20)).ToString()
                + (Convert.ToInt32(unused19)).ToString()
                + (Convert.ToInt32(unused18)).ToString()
                + (Convert.ToInt32(unused17)).ToString()
                + (Convert.ToInt32(unused16)).ToString()
                + (Convert.ToInt32(unused15)).ToString()
                + (Convert.ToInt32(unused14)).ToString()
                + (Convert.ToInt32(unused13)).ToString()
                + (Convert.ToInt32(unused12)).ToString()
                + (Convert.ToInt32(unused11)).ToString()
                + (Convert.ToInt32(overflowOnLDN)).ToString()
                + (Convert.ToInt32(overflowOnAbsolute)).ToString()
                + (Convert.ToInt32(divideByZero)).ToString()
                + (Convert.ToInt32(addressAfterStart)).ToString()
                + (Convert.ToInt32(addressBeforeStart)).ToString()
                + (Convert.ToInt32(rotateTooLarge)).ToString()
                + (Convert.ToInt32(shiftTooLarge)).ToString()
                + (Convert.ToInt32(overflowOnDivide)).ToString()
                + (Convert.ToInt32(overflowOnMultiply)).ToString()
                + (Convert.ToInt32(overflowOnSubtract)).ToString()
                + (Convert.ToInt32(overflowOnAdd)).ToString()).PadLeft(24, '0');
        }
        public string ToHex()
        {
            /*!
            Procedure Name: ToHex
            Description: Provides the hex version of the status register
            Input Parameters: none
            Output Parameters: none
            Errors Conditions Tested:
            Error Messages Generated:
            Original Author: SH, RM
            Procedure Creation Date: 11/21/2009
            Modification Log:
            Coding standards met: SR
            Testing standards met: RM
            !*/
            return Converter.ToHex(ToBin());
        }
        public int ToInt()
        {
            /*!
            Procedure Name: ToInt
            Description: Provides the integer version of the status register
            Input Parameters: none
            Output Parameters: none
            Errors Conditions Tested:
            Error Messages Generated:
            Original Author: SH, RM
            Procedure Creation Date: 11/21/2009
            Modification Log:
            Coding standards met: SR
            Testing standards met: RM
            !*/
            return Converter.ToInt(ToHex(), false);
        }
        public void SetSR(string twentyFourBitBinary)
        {
            /*!
            Procedure Name: SetSR
            Description: Allows for setting of Status Register
            Input Parameters: string twentyFourBitBinary - the binary string the SR is to be set to
            Output Parameters: none
            Errors Conditions Tested:
            Error Messages Generated:
            Original Author: SH, RM
            Procedure Creation Date: 11/22/2009
            Modification Log:
            Coding standards met: SR
            Testing standards met: RM
            !*/
            this.overflowOnAdd = (twentyFourBitBinary[23].Equals('1'));
            this.overflowOnSubtract = (twentyFourBitBinary[22].Equals('1'));
            this.overflowOnMultiply = (twentyFourBitBinary[21].Equals('1'));
            this.overflowOnDivide = (twentyFourBitBinary[20].Equals('1'));
            this.shiftTooLarge = (twentyFourBitBinary[19].Equals('1'));
            this.rotateTooLarge = (twentyFourBitBinary[18].Equals('1'));
            this.addressBeforeStart = (twentyFourBitBinary[17].Equals('1'));
            this.addressAfterStart = (twentyFourBitBinary[16].Equals('1'));
            this.divideByZero = (twentyFourBitBinary[15].Equals('1'));
            this.overflowOnAbsolute = (twentyFourBitBinary[14].Equals('1'));
            this.overflowOnLDN = (twentyFourBitBinary[13].Equals('1'));
            this.unused11 = (twentyFourBitBinary[12].Equals('1'));
            this.unused12 = (twentyFourBitBinary[11].Equals('1'));
            this.unused13 = (twentyFourBitBinary[10].Equals('1'));
            this.unused14 = (twentyFourBitBinary[9].Equals('1'));
            this.unused15 = (twentyFourBitBinary[8].Equals('1'));
            this.unused16 = (twentyFourBitBinary[7].Equals('1'));
            this.unused17 = (twentyFourBitBinary[6].Equals('1'));
            this.unused18 = (twentyFourBitBinary[5].Equals('1'));
            this.unused19 = (twentyFourBitBinary[4].Equals('1'));
            this.unused20 = (twentyFourBitBinary[3].Equals('1'));
            this.unused21 = (twentyFourBitBinary[2].Equals('1'));
            this.unused22 = (twentyFourBitBinary[1].Equals('1'));
            this.unused23 = (twentyFourBitBinary[0].Equals('1'));
        }
    }
}
